Assignment of Multiple Containers

We will do the following task:

Nginx

We can run Nginx by

docker container run -d --name proxy -p 80:80 nginx

The server should run in http://localhost/

Ref: 1. image 2. Docker run 3. Docker Detach 4. Assign Name 5. Expose Port

MySQL

We can run mySQL by

docker run -d --name db -p 3306:3306 -e MYSQL_RANDOM_ROOT_PASSWORD=yes mysql

We can look for logs

docker logs

In logs, we should find the root password

GENERATED ROOT PASSWORD: auto_generated_password

Ref:

  1. Image from Docker Hub
  2. MYSQL_RANDOM_ROOT_PASSWORD environment name Docker Hub
  3. Passing environment

Apache (httpd)

We can run the apache server by,

docker container run -d --name web_server -p 8080:80 httpd

The server should run in http://localhost:8080/.

Ref:

  1. image

Stopping all the containers

We can list down the containers by,

docker container ls

We can stop all these containers,

docker container stop <nginx-container-id> <mysql-container-id> <nginx-container-id>

Now docker container ls should return list of containers as stopped status.

Delete all the images

We can list down the containers by,

docker container ls

We can remove all these containers,

docker rm -f <nginx-container-id> <mysql-container-id> <nginx-container-id>

Now docker container ls should return empty list.